<?php
/* 打分模块 */


function getgpc($k, $var='R') {
	switch($var) {
		case 'G': $var = &$_GET; break;
		case 'P': $var = &$_POST; break;
		case 'C': $var = &$_COOKIE; break;
		case 'R': $var = &$_REQUEST; break;
	}
	return isset($var[$k]) ? $var[$k] : NULL;
}

$act = getgpc("val");
$id = getgpc("id");
if ($act == "add")
{
	$dela_mark = +1;
}
else if($act == "dec")
{
	$dela_mark = -1;
}
else
{
	header("Location: index.php");
	exit();
}

$f = fopen("data.txt", "r");
$item_str = fgets($f, 4096);
$name_str = fgets($f, 4096);
fclose($f);

$items = split(" ", $item_str);

$items[$id] += $dela_mark;
if ($items[$id] <= 0)
{
	$items[$id] = 0;
}
$item_str = "";
for ($i = 0; $i < count($items); $i++)
{
	$item_str =   $item_str . $items[$i]. " " ;
}

$item_str = trim($item_str);

$f = fopen("data.txt", "w");
fputs($f, $item_str);
fputs($f, "\r\n");
fputs($f, $name_str);
fclose($f);


header("Location: index.php");

?>

